﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MaxStudio.Concrete.Web.RPT;
using System.Data;
using System.Data.SqlClient;

using MaxStudio.Concrete.Web;
using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server;
using MaxStudio.Concrete.Server.Service;
using MaxStudio.Concrete.Server.Dao;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace MaxStudio.Concrete.Web.Pages
{
    public partial class ReportTest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             BindReport();
        }

        private void BindReport()
        {
            //RPTTemperatureAndHumidityService RPTTemperatureAndHumidityServiceObj = ServiceFactory.getRPTTemperatureAndHumidityService();
            //OperationResult<List<tb_RPT_TemperatureAndHumidity>> result = RPTTemperatureAndHumidityServiceObj.GetAllTemperatureAndHumidity();
               
            //DataSet ds = new DataSet();
            //CrystalReport1 oCR = new CrystalReport1();
            //oCR.SetDataSource(ds);
            
            //this.CrystalReportViewer1.ReportSource = oCR; 
        

            // TEST 
            TableLogOnInfo logOnInfo = new TableLogOnInfo();
            //这里必须事先申明一个ReportDocument对象 Report，同时加载数据报表
            ReportDocument oRpt = new ReportDocument();
            //获取.rpt文件真实路径
            string path;
            path = Server.MapPath("/RPT/oCRTDeviceUsing.rpt");
            oRpt.Load(path);

            //从web.config中获取logOnInfo参数信息
            string a, b, c, d;
            //获取ServerName
            a = "61.191.191.95";//System.Configuration.ConfigurationSettings.AppSettings["servername"];
            //获取DatabaseName
            b = "Concrete";//System.Configuration.ConfigurationSettings.AppSettings["database"];
            //获取UserId
            c = "scott";//System.Configuration.ConfigurationSettings.AppSettings["userid"];
            //获取password
            d = "scott";//System.Configuration.ConfigurationSettings.AppSettings["pass"];
            //设置logOnInfo参数
            logOnInfo.ConnectionInfo.ServerName = a;
            logOnInfo.ConnectionInfo.DatabaseName = b;
            logOnInfo.ConnectionInfo.UserID = c;
            logOnInfo.ConnectionInfo.Password = d;

            oRpt.Database.Tables[0].ApplyLogOnInfo(logOnInfo);

            //建立.rpt文件与CryStalReportviewer文件之间的连接
            CrystalReportViewer1.ReportSource = oRpt;

            DataBind();

        } 

    }
}
